package com.sun.umbrella.session.websession;

import com.sun.umbrella.remote.RemoteService;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.io.Serializable;

/**
 * @author Jay
 * @version v1.0
 * @description session服务代理类
 * @date 2017-12-21 09:56
 */

public class UmbrellaSessionProxy {


    @Autowired
    private RemoteService remoteService;


    @Value("${filter.enable}")
    private Boolean filterEnable;


    /**
     * 获取 web session
     *
     * @param sessionId
     * @return
     */
    public Session getSession(Serializable sessionId) {
        if (filterEnable) {
            return remoteService.getSession(sessionId);
        }
        return null;
    }


    /**
     * 创建 web session
     *
     * @param session
     * @return
     */
    public Serializable createSession(Session session) {
        if (filterEnable) {
            return remoteService.createSession(session);
        }
        return null;
    }


    /**
     * 更新 web session
     *
     * @param session
     */
    public void updateSession(Session session) {
        if (filterEnable) {
            remoteService.updateSession(session);
        }
    }


    /**
     * 删除 web session
     *
     * @param session
     */
    public void deleteSession(Session session) {
        if (filterEnable) {
            remoteService.deleteSession(session);
        }
    }

}
